home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#48 (Sep 89)
/
Zoundz Source
/
MySound.Pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1989-05-01
|
2KB
|
81 lines
unit MySound;
interface
uses
PrintTraps, Sound, MyGlobals;
{creates a 'snd ' resource}
procedure CreateSndResource (StartSel, EndSel: integer);
implementation
procedure CreateSndResource;
var
i, j: integer;
amplong, freqlong: longint;
lastTimbre: integer;
theErr: OSErr;
theSize: integer;
begin
lastTimbre := -1;
if Handle(MySoundHandle) <> nil then
begin
DisposHandle(Handle(MySoundHandle));
DisposHandle(MyHandle);
end;
MySoundHandle := MySoundHdl(NewHandle(sizeof(MySoundRec)));
with MySoundHandle^^ do
begin
format := 1; {set up header stuff}
SynthCount := 1;
SynthType := 1;
SynthInit := 0;
with MyDoc^ do
begin
j := 0;
for i := StartSel to EndSel do
begin {get sound commands}
j := j + 1;
if timbre[i] <> lastTimbre then {do we need a timbre command?}
begin
MySounds[j].cmd := timbreCmd;
MySounds[j].param1 := timbre[i];
MySounds[j].param2 := 0;
lastTimbre := timbre[i];
j := j + 1;
end; {of timbre command}
if freq[i] = 128 then {is it a rest?}
begin
MySounds[j].cmd := restCmd;
MySounds[j].param1 := dur[i];
MySounds[j].param2 := 0;
end
else {no, regular note}
begin
ampLong := amp[i];
ampLong := BitAnd(BitShift(ampLong, 24), $FF000000);
freqLong := BitAnd(freq[i], $000000FF);
MySounds[j].cmd := noteCmd;
MySounds[j].param1 := dur[i];
MySounds[j].param2 := ampLong + freqLong;
end;
end; {of for loop}
end; {with MyDoc}
j := j + 1;
MySounds[j].cmd := noteCmd; {turn off sound}
MySounds[j].param1 := 0;
MySounds[j].param2 := 0;
j := j + 1;
MySounds[j].cmd := quietCmd;
MySounds[j].param1 := 0;
MySounds[j].param2 := 0;
CommandCount := j;
end; { of with MySoundHandle}
theSize := 12 + (j * 8);
MyHandle := Handle(MySoundHandle);
theErr := HandToHand(MyHandle);
SetHandleSize(MyHandle, Size(theSize));
end; { of CreateSndResource}
end.